<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h1>Map</h1>
    <p>用于集中管理对象，采用散列的键值对来存储数据。</p>
    <h2>构造方法</h2>
    <ul>
        <li>new Map()：创建一个空的映射。</li>
        <li>new Map([...[key,value]])：使用多组键值对数组的数组，来初始化映射。</li>
    </ul>
    <h2>常用方法</h2>
    <ul>
        <li>set(key,value)：在映射中存放一组键值对，返回当前Map的引用。</li>
        <li>get(key)：根据键，获取值。如果键上不存在值，返回undefined。</li>
        <li>has(key)：判断键是否存在于map中。返回boolean。</li>
        <li>delete(key)：根据key删除一组键值对。删除成功返回true。</li>
    </ul>
    <p>以上key和value，都可以是任意数据类型。如果key是字符串的时候，实际上和object对象没有太大区别。</p>
    <h2>作业</h2>
    <dl>
        <dt>必做</dt>
        <dd>把对象转为map</dd>
    </dl>
    <script>
        let map = new Map([["name","奉先"],["age",35]]);
        console.log("map = ",map);

        console.log(map.get("xxx")); // undefined

        map.set("sex","男");
        map.set("friend",{name: "郑涛",age: 20});
        map.set("grildFriend",null);
        console.log("map = ",map);

        let value = map.get("sex");
        console.log("sex = ",value);

        value = map.delete("grildFriend");
        console.log("value = ",value); // true
        console.log(map.get("grildFriend"));


    </script>
</body>
</html>